//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.hustcad.plm.pdm.common.service.impl.search;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.hustcad.plm.basic.util.TyCommonExtUtil;
import com.hustcad.plm.basic.util.TyplmEntityBaseUtil;
import com.hustcad.plm.basic.util.TyplmLoggerUtil;
import com.hustcad.plm.pdm.attribute.model.dto.AttributeDefMapDTO;
import com.hustcad.plm.pdm.basedrule.dto.TyplmBaseRuleBoundedObjDTO;
import com.hustcad.plm.pdm.basedrule.service.TyplmBasedRuleService;
import com.hustcad.plm.pdm.classification.model.vo.TyplmClassificationAttrVO;
import com.hustcad.plm.pdm.classification.service.TyplmClassificationService;
import com.hustcad.plm.pdm.common.mapper.search.TyplmClassifySearchMapper;
import com.hustcad.plm.pdm.common.model.constant.CommonErrorCodeEnum;
import com.hustcad.plm.pdm.common.model.dto.search.ClassifyQueryParamDTO;
import com.hustcad.plm.pdm.common.model.dto.search.ObjectSearchDTO;
import com.hustcad.plm.pdm.common.model.dto.search.SearchAttributeDTO;
import com.hustcad.plm.pdm.common.model.dto.search.SearchAttributeGroupDTO;
import com.hustcad.plm.pdm.common.model.dto.search.SearchClassificationDTO;
import com.hustcad.plm.pdm.common.model.dto.search.SearchColumnDTO;
import com.hustcad.plm.pdm.common.model.dto.search.SearchConditionDTO;
import com.hustcad.plm.pdm.common.model.dto.search.SearchFieldDTO;
import com.hustcad.plm.pdm.common.model.dto.search.SearchFieldGroupDTO;
import com.hustcad.plm.pdm.common.model.dto.search.TypeConditionDTO;
import com.hustcad.plm.pdm.common.model.vo.search.ResultEntityVO;
import com.hustcad.plm.pdm.common.model.vo.search.SearchAttributeVO;
import com.hustcad.plm.pdm.common.model.vo.search.SearchClassificationVO;
import com.hustcad.plm.pdm.common.model.vo.search.SearchTypeVO;
import com.hustcad.plm.pdm.common.service.search.TyplmClassifySearchService;
import com.hustcad.plm.pdm.common.service.search.TyplmCommonSearchService;
import com.hustcad.plm.pdm.common.service.search.TyplmSearchAttributeService;
import com.hustcad.plm.pdm.common.util.CommonUtil;
import com.hustcad.plm.pdm.common.util.TyplmSearchBuildUtil;
import com.hustcad.plm.pdm.enumeration.model.vo.LocalValueVO;
import com.hustcad.plm.pdm.enumeration.service.TyplmLocalePropertyValueService;
import com.hustcad.plm.pdm.folder.model.vo.filter.TySubFolderFilterVO;
import com.hustcad.plm.pdm.folder.service.impl.search.TyplmSubFilterObjectExtendServiceImpl;
import com.hustcad.plm.pdm.iba.service.TyplmAttributeDefService;
import com.hustcad.plm.pdm.iba.service.TyplmCommonAttributeService;
import com.hustcad.plm.pdm.type.model.vo.TypeVueVO;
import com.hustcad.plm.pdm.type.service.TyplmTypeService;
import com.jsyxdl.k3cloud.listener.K3CloudHttpService;
import com.jsyxdl.service.impl.ExtendTyplmSubFilterObjectExtendServiceImpl;
import com.ty.basic.dto.TableParamDTO;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.type.ClassificationDO;
import com.ty.basic.exception.message.SystemErrorCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.ResponseCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.TyException;
import com.ty.basic.util.EntityBaseUtil;
import com.ty.basic.utils.ArgumentUtils;
import com.ty.basic.utils.ValidateUtils;
import com.ty.basic.utils.excel.converter.ListToExcel;
import com.ty.basic.vo.TyAttributeDefMapVO;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

@Service
public class TyplmClassifySearchServiceImpl implements TyplmClassifySearchService {
    private static final Logger log = LoggerFactory.getLogger(TyplmClassifySearchServiceImpl.class);
    @Resource
    private TyplmClassifySearchMapper typlmClassifySearchMapper;
    @Resource
    private TyplmTypeService typlmTypeService;
    @Resource
    private TyplmCommonSearchService typlmCommonSearchService;
    @Resource
    private TyplmSearchAttributeService typlmSearchAttributeService;
    @Resource
    private TyplmBasedRuleService typlmBasedRuleService;
    @Resource
    private TyplmAttributeDefService typlmAttributeDefService;
    @Resource
    private TyplmCommonAttributeService typlmCommonAttributeService;
    private static final String TABLE_ID = "ClassificationView";
    private static final String DISPLAY_NAME = "displayName";
    private static final String IBA_ATTR_MAP = "ibaAttrMapForSearch";
    private static final String EXT_ATTR_MAP = "extAttrMapForSearch";
    @Value("${classify.max.export.count:20000}")
    private int maxExportCount;
    @Resource
    private TyplmClassificationService typlmClassificationService;
    @Resource
    private TyplmLocalePropertyValueService typlmLocalePropertyValueService;

    public TyplmClassifySearchServiceImpl() {
    }

    public SearchClassificationVO getSearchClassificationByType(BigInteger typeOid) {
        TyplmBaseRuleBoundedObjDTO baseRule = this.typlmBasedRuleService.getBaseRuleBoundedObjInfo(typeOid);
        if (baseRule != null && !EntityBaseUtil.isEmptyOid(baseRule.getClassificationOid())) {
            List<TypeVueVO> typeVueList = this.typlmTypeService.queryTypeByIds(Collections.singletonList(typeOid));
            if (CollectionUtils.isEmpty(typeVueList)) {
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_TYPE_NOT_FOUND, new String[]{typeOid.toString()})));
            } else {
                String typeInthid = ((TypeVueVO)typeVueList.get(0)).getInthid();
                SearchClassificationVO result;
                if ("ty.inteplm.type.CTyClassificationRoot".equals(baseRule.getClassificationOtype())) {
                    result = this.typlmClassifySearchMapper.getRootSearchClassification(baseRule.getClassificationOid(), TyCommonExtUtil.getFrontLanguage());
                } else {
                    TableParamDTO tableParamDTO = EntityBaseUtil.getTableParamDTO(EntityBaseUtil.getOtypeByInthid(typeInthid));
                    result = this.typlmClassifySearchMapper.getSearchClassification(baseRule.getClassificationOid(), tableParamDTO, TyCommonExtUtil.getFrontLanguage());
                }

                if (result == null) {
                    throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_OBJECT_NOT_FOUND, new String[]{baseRule.getClassificationOid().toString()})));
                } else {
                    result.setTypeInthid(typeInthid);
                    return result;
                }
            }
        } else {
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_SEARCH_CLASSIFY_NOT_BINDING_CLASSIFICATION)));
        }
    }

    public List<SearchClassificationVO> getSearchClassificationByParent(SearchClassificationDTO searchClassificationDTO) {
        EntityBaseUtil.checkParamNotNull(searchClassificationDTO.getRootOid(), "rootOid");
        EntityBaseUtil.checkParamNotNull(searchClassificationDTO.getTypeInthid(), "TypeInthid");
        if (EntityBaseUtil.isEmptyOid(searchClassificationDTO.getOid())) {
            searchClassificationDTO.setOid(BigInteger.ZERO);
        }

        String otype = EntityBaseUtil.getOtypeByInthid(searchClassificationDTO.getTypeInthid());
        TableParamDTO tableParamDTO = EntityBaseUtil.getTableParamDTO(otype);
        return this.typlmClassifySearchMapper.querySearchClassificationByParent(searchClassificationDTO, tableParamDTO, TyCommonExtUtil.getFrontLanguage());
    }

    public List<SearchClassificationVO> getAllClassificationByParent(SearchClassificationDTO searchClassificationDTO) {
        List<SearchClassificationVO> classificationVOList = this.getSearchClassificationByParent(searchClassificationDTO);
        String otype = EntityBaseUtil.getOtypeByInthid(searchClassificationDTO.getTypeInthid());
        TableParamDTO tableParamDTO = EntityBaseUtil.getTableParamDTO(otype);
        this.setChildrenList(searchClassificationDTO, classificationVOList, tableParamDTO);
        return classificationVOList;
    }

    public void setChildrenList(SearchClassificationDTO searchClassificationDTO, List<SearchClassificationVO> parentList, TableParamDTO tableParamDTO) {
        if (!CollectionUtils.isEmpty(parentList)) {
            List<BigInteger> oidList = (List)parentList.stream().filter((item) -> {
                return item.getHasChildren();
            }).map(SearchClassificationVO::getOid).collect(Collectors.toList());
            List<SearchClassificationVO> classificationVOList = this.getSearchClassificationVOS(searchClassificationDTO, tableParamDTO, oidList);
            if (!CollectionUtils.isEmpty(classificationVOList)) {
                Map<BigInteger, List<SearchClassificationVO>> parentMap = (Map)classificationVOList.stream().collect(Collectors.groupingBy(SearchClassificationVO::getParentnodeoid));
                Iterator var7 = parentMap.entrySet().iterator();

                while(var7.hasNext()) {
                    Map.Entry<BigInteger, List<SearchClassificationVO>> entry = (Map.Entry)var7.next();
                    BigInteger oid = (BigInteger)entry.getKey();
                    List<SearchClassificationVO> valueList = (List)entry.getValue();
                    List<SearchClassificationVO> list = (List)parentList.stream().filter((item) -> {
                        return item.getOid().equals(oid);
                    }).collect(Collectors.toList());
                    if (!CollectionUtils.isEmpty(list)) {
                        list.forEach((item) -> {
                            item.setChildrenList(valueList);
                        });
                    }
                }

                this.setChildrenList(searchClassificationDTO, classificationVOList, tableParamDTO);
            }
        }
    }

    private List<SearchClassificationVO> getSearchClassificationVOS(SearchClassificationDTO searchClassificationDTO, TableParamDTO tableParamDTO, List<BigInteger> oidList) {
        if (CollectionUtils.isEmpty(oidList)) {
            return Collections.emptyList();
        } else {
            List<SearchClassificationVO> allClassificationVOList = new ArrayList();
            List<List<BigInteger>> pageList = CommonUtil.subObjectList(oidList, 500);
            pageList.forEach((list) -> {
                searchClassificationDTO.setOidList(list);
                searchClassificationDTO.setCurrent(false);
                List<SearchClassificationVO> classificationVOList = this.typlmClassifySearchMapper.queryClassificationByParentList(searchClassificationDTO, tableParamDTO, TyCommonExtUtil.getFrontLanguage());
                if (!CollectionUtils.isEmpty(classificationVOList)) {
                    allClassificationVOList.addAll(classificationVOList);
                }

            });
            return allClassificationVOList;
        }
    }

    public List<SearchClassificationVO> getSearchClassification(SearchClassificationDTO searchClassificationDTO) {
        searchClassificationDTO.setCurrent(true);
        return this.getSearchClassificationByParent(searchClassificationDTO);
    }

    public List<ResultEntityVO> queryByCondition(SearchConditionDTO conditionDTO) {
        PageInfo<ResultEntityVO> resultPage = this.queryByClafiCondition(conditionDTO, false);
        return resultPage.getList();
    }

    public PageInfo<ResultEntityVO> queryByConditionByPage(SearchConditionDTO conditionDTO) {
        return this.queryByClafiCondition(conditionDTO, conditionDTO.isNeedCount());
    }

    private PageInfo<ResultEntityVO> queryByClafiCondition(SearchConditionDTO conditionDTO, Boolean needCount) {
        if (EntityBaseUtil.isEmptyOid(conditionDTO.getClassificationOid())) {
            return new PageInfo();
        } else {
            List<SearchAttributeDTO> effectiveSearchAttributeList = TyplmSearchBuildUtil.getEffectiveSearchAttributeList(conditionDTO.getConditionGroups());
            TypeConditionDTO classifyCondition = this.initClassifyCondition(conditionDTO);
            if (!CollectionUtils.isEmpty(effectiveSearchAttributeList)) {
                TyplmSearchBuildUtil.checkConditionJoin(conditionDTO.getConditionJoint());
                this.dealSearchAttributeGroups(conditionDTO, classifyCondition);
            }

            ClassifyQueryParamDTO queryParamDTO = this.generateQueryParam(conditionDTO, classifyCondition);
            PageMethod.startPage(conditionDTO.getPageNum(), conditionDTO.getPageSize(), needCount);
            List<ResultEntityVO> list = this.typlmClassifySearchMapper.queryByCondition(queryParamDTO);


            ExtendTyplmSubFilterObjectExtendServiceImpl typlmSubFilterObjectExtendService= SpringUtil.getBean(
                    ExtendTyplmSubFilterObjectExtendServiceImpl.class);
            PageInfo<ResultEntityVO> result = new PageInfo(list);
            this.typlmCommonSearchService.dealResult(conditionDTO, result.getList());
            typlmSubFilterObjectExtendService.excuteAfterSubFilterObjectClass(result);

            return result;
        }
    }

    private TypeConditionDTO initClassifyCondition(SearchConditionDTO conditionDTO) {
        String otype = EntityBaseUtil.getOtypeByInthid(conditionDTO.getTypeInthid());
        TypeConditionDTO result = new TypeConditionDTO();
        result.generate(conditionDTO.getTypeInthid(), otype, TyplmSearchBuildUtil.changeWildcardValue(conditionDTO.getKeyword()), TyplmSearchBuildUtil.getKeyWordSymbol(conditionDTO.getSymbol(), true));
        if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(conditionDTO.getObjectSearchList())) {
            Optional<ObjectSearchDTO> searchOptional = conditionDTO.getObjectSearchList().stream().filter((item) -> {
                return otype.equals(EntityBaseUtil.getOtypeByInthid(item.getTypeInthid()));
            }).findFirst();
            if (searchOptional.isPresent()) {
                ObjectSearchDTO objectSearchDTO = (ObjectSearchDTO)searchOptional.get();
                List<BigInteger> oidList = objectSearchDTO.getOidList();
                if (ObjectUtils.isNotEmpty(oidList)) {
                    List<List<BigInteger>> listOidList = CommonUtil.subObjectList(oidList, 800);
                    result.setOidList(listOidList);
                }
            }
        }

        return result;
    }

    private void dealSearchAttributeGroups(SearchConditionDTO conditionDTO, TypeConditionDTO classifyCondition) {
        Iterator var3 = conditionDTO.getConditionGroups().iterator();

        while(var3.hasNext()) {
            SearchAttributeGroupDTO attributeGroupDTO = (SearchAttributeGroupDTO)var3.next();
            SearchFieldGroupDTO fieldGroupDTO = new SearchFieldGroupDTO(attributeGroupDTO.getConditionJoint());
            Iterator var6 = attributeGroupDTO.getConditions().iterator();

            while(var6.hasNext()) {
                SearchAttributeDTO searchAttributeDTO = (SearchAttributeDTO)var6.next();
                if (!searchAttributeDTO.isEmpty()) {
                    this.dealSearchAttributeField(conditionDTO, searchAttributeDTO, classifyCondition, fieldGroupDTO);
                }
            }

            if (!CollectionUtils.isEmpty(fieldGroupDTO.getConditions())) {
                classifyCondition.addConditionGroup(fieldGroupDTO);
            }
        }

    }

    private void dealSearchAttributeField(SearchConditionDTO conditionDTO, SearchAttributeDTO searchAttributeDTO, TypeConditionDTO classifyCondition, SearchFieldGroupDTO fieldGroupDTO) {
        SearchFieldDTO searchFieldDTO = TyplmSearchBuildUtil.buildSearchFieldDTO(conditionDTO, searchAttributeDTO, classifyCondition);
        if (searchFieldDTO != null) {
            if ("iterationid".equals(searchFieldDTO.getFieldName())) {
                classifyCondition.setNeedLasted(false);
            }

            fieldGroupDTO.addCondition(searchFieldDTO);
        }

    }

    private ClassifyQueryParamDTO generateQueryParam(SearchConditionDTO conditionDTO, TypeConditionDTO classifyCondition) {
        ClassifyQueryParamDTO queryParamDTO = new ClassifyQueryParamDTO();
        queryParamDTO.setClassificationOid(conditionDTO.getClassificationOid());
        queryParamDTO.setConditionJoint(conditionDTO.getConditionJoint());
        queryParamDTO.setCurrentUserOid(CommonUtil.getUser().getOid());
        queryParamDTO.setPageNum(conditionDTO.getPageNum());
        queryParamDTO.setPageSize(conditionDTO.getPageSize());
        queryParamDTO.setCondition(classifyCondition);
        return queryParamDTO;
    }

    public List<SearchAttributeVO> getSearchAttribute(SearchClassificationDTO classifyDTO) {
        if (!EntityBaseUtil.isEmptyOid(classifyDTO.getOid()) && !StringUtils.isEmpty(classifyDTO.getTypeInthid())) {
            List<SearchAttributeVO> result = new ArrayList();
            String otype = EntityBaseUtil.getOtypeByInthid(classifyDTO.getTypeInthid());
            List<SearchAttributeVO> attributeList = this.typlmSearchAttributeService.getSearchAttributeListByOtype(otype);
            if (!CollectionUtils.isEmpty(attributeList)) {
                Iterator var5 = attributeList.iterator();

                while(var5.hasNext()) {
                    SearchAttributeVO searchAttributeVO = (SearchAttributeVO)var5.next();
                    searchAttributeVO.setClassificationOid(classifyDTO.getOid());
                    searchAttributeVO.addType(this.getSearchTypeVOByTypeInthid(classifyDTO.getTypeInthid()));
                }

                result.addAll(attributeList);
            }

            List<AttributeDefMapDTO> attributeDefMapVOList = this.typlmCommonAttributeService.queryInheritAttributeDef(classifyDTO.getOid(), "ty.inteplm.type.CTyClassification");
            Iterator var10 = attributeDefMapVOList.iterator();

            while(var10.hasNext()) {
                AttributeDefMapDTO attributeDefMapDTO = (AttributeDefMapDTO)var10.next();
                if (!"ty.inteplm.attribute.CTyReferenceDef".equals(attributeDefMapDTO.getAttributereferenceotype()) && !"ty.inteplm.attribute.CTyBlobDef".equals(attributeDefMapDTO.getAttributereferenceotype())) {
                    SearchAttributeVO ibaAttribute = TyplmSearchBuildUtil.buildIbaAttribute(attributeDefMapDTO);
                    ibaAttribute.setClassificationOid(classifyDTO.getOid());
                    ibaAttribute.addClassification(this.getSearchTypeVOByClassificationOid(classifyDTO.getOid()));
                    result.add(ibaAttribute);
                }
            }

            result.sort(Comparator.comparing(SearchAttributeVO::getDisplayName));
            return result;
        } else {
            return new ArrayList();
        }
    }

    private SearchTypeVO getSearchTypeVOByTypeInthid(String typeInthid) {
        SearchTypeVO searchTypeVO = new SearchTypeVO();
        if (StringUtils.isBlank(typeInthid)) {
            return searchTypeVO;
        } else {
            List<TypeVueVO> typeVueVOS = this.typlmTypeService.queryTypeByInthIds(Arrays.asList(typeInthid));
            if (CollUtil.isEmpty(typeVueVOS)) {
                return searchTypeVO;
            } else {
                searchTypeVO.setDisplayName(((TypeVueVO)typeVueVOS.get(0)).getDisplayName());
                return searchTypeVO;
            }
        }
    }

    private SearchTypeVO getSearchTypeVOByClassificationOid(BigInteger classificationOid) {
        SearchTypeVO searchTypeVO = new SearchTypeVO();
        if (Objects.isNull(classificationOid)) {
            return searchTypeVO;
        } else {
            TableParamDTO tableParamDTO = EntityBaseUtil.getTableParamDTO("ty.inteplm.type.CTyClassification");
            SearchClassificationVO searchClassification = this.typlmClassifySearchMapper.getSearchClassification(classificationOid, tableParamDTO, TyCommonExtUtil.getFrontLanguage());
            if (Objects.isNull(searchClassification)) {
                return searchTypeVO;
            } else {
                searchTypeVO.setClassificationDisplayName(searchClassification.getDisplayname());
                return searchTypeVO;
            }
        }
    }

    public List<SearchColumnDTO> getSearchColumn(SearchClassificationDTO classifyDTO) {
        TyplmLoggerUtil.debug(log, () -> {
            return "获取列 入参getSearchColumn ==> classifyDTO : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(classifyDTO)};
        });
        Map<String, String> enumMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(new ArrayList(), "AdvancedColumnField", TyCommonExtUtil.getFrontLanguage());
        TyplmLoggerUtil.debug(log, () -> {
            return "查询枚举 返回参数 typlmLocalePropertyValueService.queryLocaleValueByItem <== enumMap : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(enumMap)};
        });
        List<SearchColumnDTO> result = TyplmSearchBuildUtil.buildResultColumnList(enumMap);
        if (StringUtils.isNotBlank(classifyDTO.getTypeInthid())) {
            TyplmLoggerUtil.debug(log, () -> {
                return "获取硬属性列入参 typlmSearchAttributeService.getSearchColumnListByTypeList ==> otype : 【{}】, enumMap : 【{}】";
            }, () -> {
                return new Object[]{TyplmEntityBaseUtil.getOtypeByInthid(classifyDTO.getTypeInthid()), JSONObject.toJSONString(enumMap)};
            });
            result.addAll(this.typlmSearchAttributeService.getSearchColumnListByTypeList(TyplmEntityBaseUtil.getOtypeByInthid(classifyDTO.getTypeInthid()), enumMap));
            TyplmLoggerUtil.debug(log, () -> {
                return "获取硬属性列结果 typlmSearchAttributeService.getSearchColumnListByTypeList <==【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(result)};
            });
            TyplmLoggerUtil.debug(log, () -> {
                return "获取类型入参 typlmTypeService.queryTypeByInthIds ==>【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(Collections.singletonList(classifyDTO.getTypeInthid()))};
            });
            List<TypeVueVO> typeVueVOS = this.typlmTypeService.queryTypeByInthIds(Collections.singletonList(classifyDTO.getTypeInthid()));
            TyplmLoggerUtil.debug(log, () -> {
                return "获取类型返回结果 typeVueVOS ==>【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(typeVueVOS)};
            });
            if (CollUtil.isNotEmpty(typeVueVOS)) {
                TypeVueVO typeVueVO = (TypeVueVO)typeVueVOS.get(0);
                if (Objects.nonNull(typeVueVO)) {
                    Map<String, SearchColumnDTO> typeIbaAttributeMap = new HashMap();
                    TyplmLoggerUtil.debug(log, () -> {
                        return "获取类型IBA入参 typlmAttributeDefService.queryRelatedAttrDefByType ==>类型id :【{}】, 类型:【{}】";
                    }, () -> {
                        return new Object[]{JSONObject.toJSONString(typeVueVO.getOid()), "ty.inteplm.type.CTyTypeDef"};
                    });
                    List<AttributeDefMapDTO> attributeDefList = this.typlmCommonAttributeService.queryRelatedAttributeDef(typeVueVO.getOid(), "ty.inteplm.type.CTyTypeDef");
                    TyplmLoggerUtil.debug(log, () -> {
                        return "获取IBA结果 attributeDefMapVOList <==【{}】";
                    }, () -> {
                        return new Object[]{JSONObject.toJSONString(attributeDefList)};
                    });
                    TyplmSearchBuildUtil.dealIBAColumnInfo(typeIbaAttributeMap, attributeDefList);
                    result.addAll(typeIbaAttributeMap.values());
                    if (TyplmEntityBaseUtil.isEmptyOid(classifyDTO.getOid())) {
                        TyplmLoggerUtil.debug(log, () -> {
                            return "查询类型绑定的初始化规则 入参 typlmBasedRuleService.getBaseRuleBoundedObjInfo ==>类型id :【{}】, containerID:【{}】, containerOtype:【{}】";
                        }, () -> {
                            return new Object[]{JSONObject.toJSONString(typeVueVO.getOid()), JSONObject.toJSONString(BigInteger.ZERO), ""};
                        });
                        TyplmBaseRuleBoundedObjDTO baseRuleBoundedObjInfo = this.typlmBasedRuleService.getBaseRuleBoundedObjInfo(typeVueVO.getOid(), BigInteger.ZERO, "");
                        TyplmLoggerUtil.debug(log, () -> {
                            return "查询类型绑定的初始化规则 返回结果 typlmBasedRuleService.getBaseRuleBoundedObjInfo <== 【{}】";
                        }, () -> {
                            return new Object[]{JSONObject.toJSONString(baseRuleBoundedObjInfo)};
                        });
                        classifyDTO.setOid(baseRuleBoundedObjInfo.getClassificationOid());
                    }
                }
            }
        }

        if (!TyplmEntityBaseUtil.isEmptyOid(classifyDTO.getOid())) {
            Map<String, SearchColumnDTO> ibaAttributeMap = new HashMap();
            TyplmLoggerUtil.debug(log, () -> {
                return "获取分类IBA入参 typlmAttributeDefService.queryRelatedAttrDefByType ==>分类id :【{}】, 类型:【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(classifyDTO.getOid()), "ty.inteplm.type.CTyClassification"};
            });
            List<AttributeDefMapDTO> attributeDefList = this.typlmCommonAttributeService.queryRelatedAttributeDef(classifyDTO.getOid(), "ty.inteplm.type.CTyClassification");
            TyplmLoggerUtil.debug(log, () -> {
                return "获取分类IBA结果 attributeDefMapVOList <==【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(attributeDefList)};
            });
            TyplmSearchBuildUtil.dealIBAColumnInfo(ibaAttributeMap, attributeDefList);
            result.addAll(ibaAttributeMap.values());
        }

        TyplmLoggerUtil.debug(log, () -> {
            return "获取列 <== List<SearchColumnDTO> result : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(result)};
        });
        return result;
    }

    private List<SearchColumnDTO> getSearchColumnByInthidAndClassifyOid(SearchClassificationDTO classifyDTO) {
        TyplmLoggerUtil.debug(log, () -> {
            return "getSearchColumnByInthidAndClassifyOid ==> classifyDTO : 【{}】";
        }, () -> {
            return new Object[]{JSON.toJSONString(classifyDTO)};
        });
        Map<String, String> enumMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(new ArrayList(), "AdvancedColumnField", TyCommonExtUtil.getFrontLanguage());
        TyplmLoggerUtil.debug(log, () -> {
            return "typlmLocalePropertyValueService.queryLocaleValueByItem <== enumMap : 【{}】";
        }, () -> {
            return new Object[]{JSON.toJSONString(enumMap)};
        });
        List<SearchColumnDTO> result = TyplmSearchBuildUtil.buildResultColumnList(enumMap);
        if (StringUtils.isNotBlank(classifyDTO.getTypeInthid())) {
            result.addAll(this.typlmSearchAttributeService.getSearchColumnListByTypeList(TyplmEntityBaseUtil.getOtypeByInthid(classifyDTO.getTypeInthid()), enumMap));
            List<TypeVueVO> typeVueVOS = this.typlmTypeService.queryTypeByInthIds(Collections.singletonList(classifyDTO.getTypeInthid()));
            if (CollUtil.isNotEmpty(typeVueVOS)) {
                TypeVueVO typeVueVO = (TypeVueVO)typeVueVOS.get(0);
                if (Objects.nonNull(typeVueVO)) {
                    TyplmLoggerUtil.debug(log, () -> {
                        return "getSearchColumnByInthidAndClassifyOid ==> typeVueVO : 【{}】";
                    }, () -> {
                        return new Object[]{JSON.toJSONString(typeVueVO)};
                    });
                    Map<String, SearchColumnDTO> typeIbaAttributeMap = new HashMap();
                    List<AttributeDefMapDTO> attributeDefList = this.typlmCommonAttributeService.queryInheritAttributeDef(typeVueVO.getOid(), "ty.inteplm.type.CTyTypeDef");
                    TyplmSearchBuildUtil.dealIBAColumnInfo(typeIbaAttributeMap, attributeDefList);
                    result.addAll(typeIbaAttributeMap.values());
                    if (TyplmEntityBaseUtil.isEmptyOid(classifyDTO.getOid())) {
                        TyplmLoggerUtil.debug(log, () -> {
                            return "getSearchColumnByInthidAndClassifyOid分类为为空，获取初始化规则绑定的分类";
                        }, () -> {
                            return new Object[0];
                        });
                        TyplmBaseRuleBoundedObjDTO baseRuleBoundedObjInfo = this.typlmBasedRuleService.getBaseRuleBoundedObjInfo(typeVueVO.getOid(), BigInteger.ZERO, "");
                        TyplmLoggerUtil.debug(log, () -> {
                            return "getSearchColumnByInthidAndClassifyOid ==> classificationOid : 【{}】";
                        }, () -> {
                            return new Object[]{baseRuleBoundedObjInfo.getClassificationOid()};
                        });
                        classifyDTO.setOid(baseRuleBoundedObjInfo.getClassificationOid());
                    }
                }
            }
        }

        if (!TyplmEntityBaseUtil.isEmptyOid(classifyDTO.getOid())) {
            Map<String, SearchColumnDTO> ibaAttributeMap = new HashMap();
            List<AttributeDefMapDTO> attributeDefList = this.typlmCommonAttributeService.queryInheritAttributeDef(classifyDTO.getOid(), "ty.inteplm.type.CTyClassification");
            TyplmSearchBuildUtil.dealIBAColumnInfo(ibaAttributeMap, attributeDefList);
            result.addAll(ibaAttributeMap.values());
        }

        TyplmLoggerUtil.debug(log, () -> {
            return "getSearchColumnByInthidAndClassifyOid <== List<SearchColumnDTO> result : 【{}】";
        }, () -> {
            return new Object[]{JSON.toJSONString(result)};
        });
        return result;
    }

    public List<SearchColumnDTO> getSearchClassificationColumn(SearchClassificationDTO searchClassificationDTO) {
        ArgumentUtils.checkArgumentNull(searchClassificationDTO, "searchClassificationDTO");
        ArgumentUtils.checkArgumentBlank(searchClassificationDTO.getTypeInthid(), "searchClassificationDTO.typeInthid");
        ArgumentUtils.checkArgumentBlank(searchClassificationDTO.getOid(), "searchClassificationDTO.oid");
        TyplmLoggerUtil.debug(log, () -> {
            return "getSearchClassificationColumn的入参为==> 【{}】";
        }, () -> {
            return new Object[]{JSON.toJSONString(searchClassificationDTO)};
        });
        SearchTypeVO searchTypeVO = new SearchTypeVO();
        searchTypeVO.setInthid(searchClassificationDTO.getTypeInthid());
        List<SearchColumnDTO> defeatSearchColumnList = this.getDefeatSearchColumnByType(searchTypeVO);
        if (CollUtil.isEmpty(defeatSearchColumnList)) {
            return Collections.emptyList();
        } else {
            TyplmLoggerUtil.debug(log, () -> {
                return "getSearchClassificationColumn的默认展示列defeatSearchColumnList为==> 【{}】";
            }, () -> {
                return new Object[]{defeatSearchColumnList.size()};
            });
            List<SearchColumnDTO> allSearchColumnList = this.getSearchColumnByInthidAndClassifyOid(searchClassificationDTO);
            if (CollUtil.isEmpty(allSearchColumnList)) {
                return Collections.emptyList();
            } else {
                TyplmLoggerUtil.debug(log, () -> {
                    return "getSearchClassificationColumn的全部展示列allSearchColumnList为==> 【{}】";
                }, () -> {
                    return new Object[]{allSearchColumnList.size()};
                });
                Set<BigInteger> allSet = (Set)allSearchColumnList.stream().filter((itemx) -> {
                    return !TyplmEntityBaseUtil.isEmptyOid(itemx.getIbaDefOid());
                }).map(SearchColumnDTO::getIbaDefOid).collect(Collectors.toSet());
                TyplmLoggerUtil.debug(log, () -> {
                    return "getSearchClassificationColumn的全部展示列中包含ibaDefOid的数据共==> 【{}】";
                }, () -> {
                    return new Object[]{JSON.toJSONString(allSet)};
                });
                List<SearchColumnDTO> returnList = new ArrayList();
                Iterator var7 = defeatSearchColumnList.iterator();

                while(var7.hasNext()) {
                    SearchColumnDTO item = (SearchColumnDTO)var7.next();
                    if (TyplmEntityBaseUtil.isEmptyOid(item.getIbaDefOid())) {
                        returnList.add(item);
                    } else {
                        TyplmLoggerUtil.debug(log, () -> {
                            return "getSearchClassificationColumn的默认展示列中iba的属性定义ibaDefOid为==> 【{}】";
                        }, () -> {
                            return new Object[]{item.getIbaDefOid()};
                        });
                        if (CollUtil.contains(allSet, item.getIbaDefOid())) {
                            returnList.add(item);
                        }
                    }
                }

                TyplmLoggerUtil.debug(log, () -> {
                    return "getSearchClassificationColumn的出参为<== 【{}】";
                }, () -> {
                    return new Object[]{JSON.toJSONString(returnList)};
                });
                return returnList;
            }
        }
    }

    public List<SearchColumnDTO> getDefeatSearchColumn(List<SearchTypeVO> list) {
        List<SearchColumnDTO> result = new ArrayList();
        if (!CollectionUtils.isEmpty(list)) {
            this.getSearchColumnByTypeList(list, result);
        }

        return result;
    }

    public List<SearchColumnDTO> getSearchColumn(List<SearchTypeVO> list) {
        List<SearchColumnDTO> result = new ArrayList();
        if (!CollectionUtils.isEmpty(list)) {
            this.getSearchColumnByTypeList(list, result);
            if (ObjectUtils.isEmpty(result)) {
                return Collections.emptyList();
            }

            this.getIbaAttributeInfo(list, result);
        }

        return result;
    }

    private void getSearchColumnByTypeList(List<SearchTypeVO> list, List<SearchColumnDTO> result) {
        Iterator var3 = list.iterator();

        while(var3.hasNext()) {
            SearchTypeVO typeVO = (SearchTypeVO)var3.next();
            this.querySearchColumnByInthId(typeVO, result);
        }

    }

    private void getSearchColumnList(List<TySubFolderFilterVO> tySubFolderFilterVOList, List<SearchColumnDTO> result) {
        if (!ObjectUtils.isEmpty(tySubFolderFilterVOList)) {
            Iterator var3 = tySubFolderFilterVOList.iterator();

            while(var3.hasNext()) {
                TySubFolderFilterVO subFolderFilterVO = (TySubFolderFilterVO)var3.next();
                byte[] theTableColumnDefinition = subFolderFilterVO.getThetablecolumndefinition();
                if (ObjectUtils.isNotEmpty(theTableColumnDefinition)) {
                    List<SearchColumnDTO> searchColumnList = JSON.parseArray(new String(theTableColumnDefinition, StandardCharsets.UTF_8), SearchColumnDTO.class);
                    subFolderFilterVO.setSearchColumnList(searchColumnList);
                }
            }

            TySubFolderFilterVO tySubFolderFilterVO = (TySubFolderFilterVO)tySubFolderFilterVOList.get(0);
            if (tySubFolderFilterVO.getSearchColumnList() == null) {
                throw CommonErrorCodeEnum.SEARCH_COLUMN_LIST_NULL.getException(new Object[0]);
            }

            result.addAll(tySubFolderFilterVO.getSearchColumnList());
        }

    }

    private void getIbaAttributeInfo(List<SearchTypeVO> list, List<SearchColumnDTO> result) {
        Map<String, SearchColumnDTO> ibaAttributeMap = new HashMap();
        Iterator var4 = list.iterator();

        while(var4.hasNext()) {
            SearchTypeVO typeVO = (SearchTypeVO)var4.next();
            this.queryIbaAttrInfoByClassOid(typeVO, ibaAttributeMap);
        }

        result.addAll(ibaAttributeMap.values());
    }

    public Integer getClassifyMaxExportCount() {
        return this.maxExportCount;
    }

    public void exportByCondition(SearchConditionDTO conditionDTO, HttpServletResponse response) {
        try {
            conditionDTO.setPageNum(1);
            conditionDTO.setPageSize(this.maxExportCount);
            List<ResultEntityVO> resultEntityVOList = this.queryByCondition(conditionDTO);
            if (!ObjectUtils.isEmpty(resultEntityVOList)) {
                Map<String, String> columnMaps = this.getDisplayColumnLists(conditionDTO);
                String typeName = this.getTypeName(conditionDTO);
                String classificationName = this.getClassificationName(conditionDTO);
                String fileName = typeName + "-" + classificationName + ".xlsx";
                this.checkFileName(fileName);
                String sheetName = classificationName + "-" + resultEntityVOList.size();
                ListToExcel.listToXslxExcel(resultEntityVOList, columnMaps, response, fileName, sheetName, Arrays.asList("ibaAttrMapForSearch", "extAttrMapForSearch"));
            }
        } catch (Throwable var9) {
            throw var9;
        }
    }

    private void checkFileName(String fileName) {
        ValidateUtils.checkStrIsBlank(fileName, SystemErrorCodeEnum.EXCEL_NAME_CANNOT_EMPTY, new Object[]{"文件"});
        ValidateUtils.checkStrByLength(fileName, 255, SystemErrorCodeEnum.EXCEL_NAME_LENGTH, new Object[]{"文件", 255});
        ValidateUtils.checkStrBySpecialCharacter(fileName, ".*([\\:\\\\/?\\*<>|]).*", SystemErrorCodeEnum.EXCEL_NAME_SPECIAL_CHARACTERS, new Object[]{"文件", "/\\:*?<>|"});
    }

    private String getTypeName(SearchConditionDTO conditionDTO) {
        if (StringUtils.isNotBlank(conditionDTO.getTypeInthid())) {
            List<String> inthIdList = new ArrayList();
            inthIdList.add(conditionDTO.getTypeInthid());
            List<TypeVueVO> typeVoList = this.typlmTypeService.queryTypeByInthIds(inthIdList);
            if (!CollectionUtils.isEmpty(typeVoList)) {
                return ((TypeVueVO)typeVoList.get(0)).getDisplayName();
            }
        }

        return "";
    }

    private String getClassificationName(SearchConditionDTO conditionDTO) {
        IdentifierEntity identifierEntity = new IdentifierEntity();
        identifierEntity.setOid(conditionDTO.getClassificationOid());
        identifierEntity.setOtype("ty.inteplm.type.CTyClassification");
        LocalValueVO localValueVO = this.typlmLocalePropertyValueService.queryTypeLocalePropertyValue(identifierEntity, "displayName");
        if (StringUtils.isNotEmpty(localValueVO.getZhCn())) {
            return localValueVO.getZhCn();
        } else if (StringUtils.isNotEmpty(localValueVO.getValue())) {
            return localValueVO.getValue();
        } else {
            List<TyplmClassificationAttrVO> classificationAttrVoLists = this.typlmClassificationService.getClassifyAttrByOid(conditionDTO.getClassificationOid());
            if (ObjectUtils.isEmpty(classificationAttrVoLists)) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_CATEGORY_NAME_NOT_FOUND, new String[0]);
            }

            String categoryName = ((TyplmClassificationAttrVO)classificationAttrVoLists.get(0)).getCategoryName();
            List<ClassificationDO> classificationDOList = this.typlmClassificationService.queryClassificationByName(categoryName);
            if (ObjectUtils.isEmpty(classificationDOList)) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_CATEGORY_NAME_NOT_FOUND, new String[]{categoryName});
            }

            return ((ClassificationDO)classificationDOList.get(0)).getName();
        }
    }

    private Map<String, String> getDisplayColumnLists(SearchConditionDTO conditionDTO) {
        List<SearchColumnDTO> columns = conditionDTO.getColumns();
        if (ObjectUtils.isEmpty(columns)) {
            throw CommonErrorCodeEnum.SEARCH_COLUMN_LIST_NULL.getException(new Object[0]);
        } else {
            return (Map)columns.stream().filter((obj) -> {
                return Objects.nonNull(obj.getPropertyName());
            }).filter((obj) -> {
                return Objects.nonNull(obj.getDisplayName());
            }).collect(Collectors.toMap(SearchColumnDTO::getPropertyName, SearchColumnDTO::getDisplayName, (key1, key2) -> {
                return key1;
            }, LinkedHashMap::new));
        }
    }

    private void querySearchColumnByInthId(SearchTypeVO typeVO, List<SearchColumnDTO> result) {
        if (StringUtils.isNotBlank(typeVO.getInthid())) {
            String inthId = EntityBaseUtil.getOtypeByInthid(typeVO.getInthid());
            List<TySubFolderFilterVO> tySubFolderFilterVOList = this.typlmClassifySearchMapper.queryViewDescriptorByDefaultType("ClassificationView", inthId);
            this.getSearchColumnList(tySubFolderFilterVOList, result);
        }

    }

    private void queryIbaAttrInfoByClassOid(SearchTypeVO typeVO, Map<String, SearchColumnDTO> ibaAttributeMap) {
        List<TyAttributeDefMapVO> attributeDefMapVOList = this.typlmAttributeDefService.queryRelatedAttrDefByType(typeVO.getClassificationOid(), "ty.inteplm.type.CTyClassification");
        Iterator var4 = attributeDefMapVOList.iterator();

        while(var4.hasNext()) {
            TyAttributeDefMapVO attributeDefMapVO = (TyAttributeDefMapVO)var4.next();
            if (!"ty.inteplm.attribute.CTyReferenceDef".equals(attributeDefMapVO.getAttributereferenceotype()) && !"ty.inteplm.attribute.CTyBlobDef".equals(attributeDefMapVO.getAttributereferenceotype())) {
                String key = attributeDefMapVO.getAttributereferenceoid().toString();
                ibaAttributeMap.computeIfAbsent(key, (k) -> {
                    SearchColumnDTO columnDTO = new SearchColumnDTO();
                    columnDTO.setPropertyName(key);
                    columnDTO.setDisplayName(TyplmEntityBaseUtil.getDisplayName(attributeDefMapVO.getIbaDefName(), attributeDefMapVO.getIbaDefDisplayName()));
                    columnDTO.setIbaDefOid(attributeDefMapVO.getAttributereferenceoid());
                    columnDTO.setIbaDefOtype(attributeDefMapVO.getAttributereferenceotype());
                    return columnDTO;
                });
            }
        }

    }

    public List<SearchColumnDTO> getDefeatSearchColumnByType(SearchTypeVO typeVO) {
        List<SearchColumnDTO> result = new ArrayList();
        this.querySearchColumnByInthId(typeVO, result);
        return result;
    }

    public List<SearchColumnDTO> getSearchColumnAndIbaAttrInfo(SearchTypeVO typeVO) {
        List<SearchColumnDTO> result = new ArrayList();
        this.querySearchColumnByInthId(typeVO, result);
        if (ObjectUtils.isEmpty(result)) {
            return Collections.emptyList();
        } else {
            Map<String, SearchColumnDTO> ibaAttributeMap = new HashMap();
            this.queryIbaAttrInfoByClassOid(typeVO, ibaAttributeMap);
            result.addAll(ibaAttributeMap.values());
            return result;
        }
    }
}
